/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ria.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import ria.Event;
import ria.RiaPackage;
import ria.UIModel;
import ria.WLayout;
import ria.Widget;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>UI Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ria.impl.UIModelImpl#getTechnology <em>Technology</em>}</li>
 *   <li>{@link ria.impl.UIModelImpl#getInterface <em>Interface</em>}</li>
 *   <li>{@link ria.impl.UIModelImpl#getMainLayout <em>Main Layout</em>}</li>
 *   <li>{@link ria.impl.UIModelImpl#getModelEvents <em>Model Events</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class UIModelImpl extends EObjectImpl implements UIModel {
	/**
	 * The default value of the '{@link #getTechnology() <em>Technology</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTechnology()
	 * @generated
	 * @ordered
	 */
	protected static final String TECHNOLOGY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getTechnology() <em>Technology</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTechnology()
	 * @generated
	 * @ordered
	 */
	protected String technology = TECHNOLOGY_EDEFAULT;

	/**
	 * The cached value of the '{@link #getInterface() <em>Interface</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInterface()
	 * @generated
	 * @ordered
	 */
	protected EList<Widget> interface_;

	/**
	 * The cached value of the '{@link #getMainLayout() <em>Main Layout</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMainLayout()
	 * @generated
	 * @ordered
	 */
	protected WLayout mainLayout;

	/**
	 * The cached value of the '{@link #getModelEvents() <em>Model Events</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModelEvents()
	 * @generated
	 * @ordered
	 */
	protected EList<Event> modelEvents;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected UIModelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return RiaPackage.Literals.UI_MODEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getTechnology() {
		return technology;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTechnology(String newTechnology) {
		String oldTechnology = technology;
		technology = newTechnology;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RiaPackage.UI_MODEL__TECHNOLOGY, oldTechnology, technology));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Widget> getInterface() {
		if (interface_ == null) {
			interface_ = new EObjectContainmentEList<Widget>(Widget.class, this, RiaPackage.UI_MODEL__INTERFACE);
		}
		return interface_;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public WLayout getMainLayout() {
		return mainLayout;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetMainLayout(WLayout newMainLayout, NotificationChain msgs) {
		WLayout oldMainLayout = mainLayout;
		mainLayout = newMainLayout;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, RiaPackage.UI_MODEL__MAIN_LAYOUT, oldMainLayout, newMainLayout);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMainLayout(WLayout newMainLayout) {
		if (newMainLayout != mainLayout) {
			NotificationChain msgs = null;
			if (mainLayout != null)
				msgs = ((InternalEObject)mainLayout).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - RiaPackage.UI_MODEL__MAIN_LAYOUT, null, msgs);
			if (newMainLayout != null)
				msgs = ((InternalEObject)newMainLayout).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - RiaPackage.UI_MODEL__MAIN_LAYOUT, null, msgs);
			msgs = basicSetMainLayout(newMainLayout, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RiaPackage.UI_MODEL__MAIN_LAYOUT, newMainLayout, newMainLayout));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Event> getModelEvents() {
		if (modelEvents == null) {
			modelEvents = new EObjectContainmentEList<Event>(Event.class, this, RiaPackage.UI_MODEL__MODEL_EVENTS);
		}
		return modelEvents;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case RiaPackage.UI_MODEL__INTERFACE:
				return ((InternalEList<?>)getInterface()).basicRemove(otherEnd, msgs);
			case RiaPackage.UI_MODEL__MAIN_LAYOUT:
				return basicSetMainLayout(null, msgs);
			case RiaPackage.UI_MODEL__MODEL_EVENTS:
				return ((InternalEList<?>)getModelEvents()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case RiaPackage.UI_MODEL__TECHNOLOGY:
				return getTechnology();
			case RiaPackage.UI_MODEL__INTERFACE:
				return getInterface();
			case RiaPackage.UI_MODEL__MAIN_LAYOUT:
				return getMainLayout();
			case RiaPackage.UI_MODEL__MODEL_EVENTS:
				return getModelEvents();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case RiaPackage.UI_MODEL__TECHNOLOGY:
				setTechnology((String)newValue);
				return;
			case RiaPackage.UI_MODEL__INTERFACE:
				getInterface().clear();
				getInterface().addAll((Collection<? extends Widget>)newValue);
				return;
			case RiaPackage.UI_MODEL__MAIN_LAYOUT:
				setMainLayout((WLayout)newValue);
				return;
			case RiaPackage.UI_MODEL__MODEL_EVENTS:
				getModelEvents().clear();
				getModelEvents().addAll((Collection<? extends Event>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case RiaPackage.UI_MODEL__TECHNOLOGY:
				setTechnology(TECHNOLOGY_EDEFAULT);
				return;
			case RiaPackage.UI_MODEL__INTERFACE:
				getInterface().clear();
				return;
			case RiaPackage.UI_MODEL__MAIN_LAYOUT:
				setMainLayout((WLayout)null);
				return;
			case RiaPackage.UI_MODEL__MODEL_EVENTS:
				getModelEvents().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case RiaPackage.UI_MODEL__TECHNOLOGY:
				return TECHNOLOGY_EDEFAULT == null ? technology != null : !TECHNOLOGY_EDEFAULT.equals(technology);
			case RiaPackage.UI_MODEL__INTERFACE:
				return interface_ != null && !interface_.isEmpty();
			case RiaPackage.UI_MODEL__MAIN_LAYOUT:
				return mainLayout != null;
			case RiaPackage.UI_MODEL__MODEL_EVENTS:
				return modelEvents != null && !modelEvents.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (technology: ");
		result.append(technology);
		result.append(')');
		return result.toString();
	}

} //UIModelImpl
